package com.karolak.stock.oscilator;

import com.karolak.stock.data.DataManager;
import com.karolak.stock.indicator.Indicator;

public class BandTrOsc extends Oscilator {

	private Indicator lowBand;
	private Indicator highBand;

	public BandTrOsc(String name, DataManager dataManager, Indicator input, Indicator lowBand, Indicator highBand) {
		super(dataManager, 0, input);
		this.lowBand = lowBand;
		this.highBand = highBand;
		setName(name);
	}

	@Override
	public double execute(double x) {
		double v = getDataManager().getLast(getInput().getName());
		double lB = getDataManager().getLast(getLowBand().getName());
		double hB = getDataManager().getLast(getHighBand().getName());

		if (lB < v && v < hB) {
			return 0;
		}
		
		double down = v - lB;
		double up = v - hB;

		double value = 0;
		if (down < 0) {
			value = down;
		} else if (up > 0) {
			value = up;
		}
		return value;
	}

	protected Indicator getLowBand() {
		return lowBand;
	}

	protected Indicator getHighBand() {
		return highBand;
	}
}
